package com.yzy.fly.entity.role;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yzy.fly.kernel.model.FlyBasicModel;
import com.yzy.fly.jarPackage.FileAccess;
import com.yzy.fly.type.FileType;
import com.yzy.fly.util.DateUtil;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@TableName(value = "fly_service", autoResultMap = true)
public class FlyService extends FlyBasicModel<Integer,FlyService> implements FileAccess {

    @TableId(type = IdType.AUTO)
    private Integer id;
    private String label;
    private String name;

    private String packageName;
    private String className;
    private String requestMapping;
//    @ParentId
    private Integer parentId;
    private Integer systemId;
    private String descr;

    @JSONField(name="children")
    @TableField(exist=false)
    private List<FlyServiceMethod> methods = new ArrayList<>(0);

    @DateTimeFormat(pattern= DateUtil.DateFormatPattern.yyyy_MM_dd_HH_mm_ss)
    @JsonFormat( pattern = DateUtil.DateFormatPattern.yyyy_MM_dd_HH_mm_ss )
    private Date createTime;
    @DateTimeFormat(pattern= DateUtil.DateFormatPattern.yyyy_MM_dd_HH_mm_ss)
    @JsonFormat( pattern = DateUtil.DateFormatPattern.yyyy_MM_dd_HH_mm_ss )
    private Date updateTime;

    @Override
    public String getFileName() {
        return getClassName();
    }

    @Override
    public String getFileSuffix() {
        return FileType.CLASS.getValue();
    }

    @Override
    public String getFilePath() {
        return (getPackageName()+ "."+ getClassName()).replace(".","/");
    }

    @Override
    public String getFileFullPath() {
        return getFilePath() + getFileSuffix();
    }

    public String getLabel(){
        return name;
    }
}
